<template>
  <div class="box">
    <table class="tb">
      <tr>
        <th>编号</th>
        <th>品牌名称</th>
        <th>创建时间</th>
        <th>操作</th>
      </tr>

      <tr v-for="(item, index) in list" :key="item.id">
        <td>{{ item.id }}</td>
        <td>{{ item.name }}</td>
        <td>{{ item.time }}</td>
        <td>
          <button @click="Del(index)">删除</button>
        </td>
      </tr>
      <tr v-if="list.length === 0">
        <td colspan="4">都让你删完了~~</td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [
        { id: 1, name: "奔驰", time: new Date().toLocaleString() },
        { id: 2, name: "福特", time: new Date().toLocaleString() },
        { id: 3, name: "五菱", time: new Date() },
      ],
    };
  },

  methods: {
    Del(index) {
      this.list.splice(index, 1);
    },
  },
};
</script>

<style>
.box {
  width: 600px;
  margin: 10px auto;
}

.tb {
  border-collapse: collapse;
  width: 100%;
}

.tb th {
  background-color: #16c27d;
  color: white;
}

.tb td,
.tb th {
  padding: 5px;
  border: 1px solid black;
  text-align: center;
}

.add {
  padding: 5px;
  border: 1px solid black;
  margin-bottom: 10px;
}
</style>